home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / c / quitlav.c < prev    next >
C/C++ Source or Header  |  2000-05-27  |  775b  |  40 lines

  1. #include <exec/exec.h>
  2. #include <clib/exec_protos.h>
  3.  
  4. #include "lavd.h"
  5.  
  6. static const char    PortName[] = "lavd";
  7. struct MsgPort    *lavdPort = NULL;
  8. struct MsgPort    *RepPort = NULL;    /* Reply port. */
  9. lavdMsg    Req;
  10.  
  11. main()
  12. {
  13.  
  14.     if ((RepPort = CreateMsgPort()) == NULL) {
  15.         PutStr("Couldn't create a message port.\n");
  16.         goto exitmain;
  17.     }
  18.     Req.lm_Message.mn_ReplyPort = RepPort;
  19.     Req.lm_Message.mn_Length = sizeof(lavdMsg);
  20.     Req.Class = LAV_STOP;
  21.  
  22.     /* Forbid so the port doesn't go away... */
  23.     Forbid();
  24.     if ((lavdPort = FindPort(PortName)) == NULL) {
  25.         Permit();
  26.         PutStr("Demon not running.\n");
  27.         goto exitmain;
  28.     }
  29.     PutMsg (lavdPort, &Req);
  30.     Permit();
  31.  
  32.     WaitPort(RepPort);    /* Wait for the reply. */
  33.  
  34.       exitmain:
  35.     if (RepPort != NULL) {
  36.         DeleteMsgPort(RepPort);
  37.     }
  38.     exit(0);
  39. }
  40.